%%testing testing
% type help '???' to read documentation

%Load data
d = LoadData('data8.bin');

%double-ize the data
[v,t] = ecg_normalize(d);

%filter signal
[v3 v2 v1] = ecg_filter(v);

figure(1)
subplot(411),plot(t,v),legend('raw signal'),xlim([15 25])
title('Filtering'),ylabel('Voltage / V'),xlim([15 25])

subplot(412),plot(t,v1),legend('Stage 1'),xlim([15 25])

subplot(413),plot(t,v2),legend('Stage 1'),xlim([15 25])

subplot(414),plot(t,v3),legend('Stage 1'),xlim([15 25])
xlabel('time / s')

%find Heart rate
[hr rate_hr] = hrc(v3);

figure(2)
ts = cumsum(60./rate_hr);
vs = 0%sampled2continuous(v3,1/550,ts);

plot(	t,v3,...
	ts,vs,'x','markersize',15,'linewidth',3);
legend('signal','R Peaks');
xlim([15 25])
title(sprintf('Heart rate = %d/min',hr))
xlabel('time / s'),ylabel('Voltage / V')

%find QRS peaks
figure(3)
ecg_peaks(v3);
title('QRS Peaks'),xlabel('time / s'),ylabel('Voltage / V')
